import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class UserInterface extends JPanel{
	static int mouseX = 0, mouseY = 0;
	static final int IMAGE_SIZE = 32;
	public String details;
	public static boolean wtf = true;

	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		this.setBackground(Color.CYAN);
		if(wtf){
			addMouseListener(new MouseClass());
			wtf = false;
		}

		boardGraphic(g);

		drawPlayerMove(g);
	}


	public void boardGraphic(Graphics g){
		Image boardImage;
		boardImage = new ImageIcon("BoardImage.png").getImage();
		
		for(int i = 0; i < Board.GOBAN_SIZE; i++){
			for(int j = 0; j < Board.GOBAN_SIZE; j++){
				g.drawImage(boardImage, i*IMAGE_SIZE, j*IMAGE_SIZE, IMAGE_SIZE, IMAGE_SIZE, this);
			}
		}
	}
	
	public void drawPlayerMove(Graphics g){
		for(int i = 0; i < Board.GOBAN_SIZE; i++){
			for(int j = 0; j < Board.GOBAN_SIZE; j++){
				if(Board.goban[i][j] == 2){
					drawBlackPlayerMove(i * IMAGE_SIZE, j * IMAGE_SIZE, g);
				}else if(Board.goban[i][j] == 1){
					drawWhitePlayerMove(i * IMAGE_SIZE, j * IMAGE_SIZE, g);
				}
			}
		}
	}

	public void drawBlackPlayerMove(int x, int y, Graphics g){
		Image blackPlayerMove;
		blackPlayerMove = new ImageIcon("BlackPlayerImage.png").getImage();
		g.drawImage(blackPlayerMove, x/IMAGE_SIZE*IMAGE_SIZE, y/IMAGE_SIZE*IMAGE_SIZE, IMAGE_SIZE, IMAGE_SIZE, this);
	}
	
	public void drawWhitePlayerMove(int x, int y, Graphics g){
		Image WhitePlayerMove;
		WhitePlayerMove = new ImageIcon("WhitePlayerImage.png").getImage();
		g.drawImage(WhitePlayerMove, x/IMAGE_SIZE*IMAGE_SIZE, y/IMAGE_SIZE*IMAGE_SIZE, IMAGE_SIZE, IMAGE_SIZE, this);
	}
	
	private class MouseClass extends MouseAdapter{
		public void mouseClicked(MouseEvent e){
			if(e.isAltDown()){
				mouseX = e.getX();
				mouseY = e.getY();
				Move.play(mouseX, mouseY);
	
				repaint();
			}			
		}	
		
		public void mouseReleased(MouseEvent e) {
			mouseX = e.getX();
			mouseY = e.getY();
			Move.play(mouseX, mouseY);
			
			repaint();	
		}
	}
}

